<template>
  <div id="windowSinglePackageSourceParseManage" class="windowEditorTab">

    <el-input v-model="$store.state.obj_setting_map.single_package_source_link" disabled placeholder="单包源分析地址"
              style="margin-bottom: 8px"/>
    <el-input v-model="rpm_name" placeholder="输入软件包名称" @keydown.enter="get_single_package_source_info"
              :disabled="parse_loading">
      <template #prepend>
        <el-date-picker v-model="date_str" type="date" placeholder="选择日期（默认为今天）" :disabled-date="disabledDate"
                        :shortcuts="shortcuts" format="YYYYMMDD" value-format="YYYYMMDD"/>
      </template>
      <template #append>
        <el-button @click="get_single_package_source_info" :loading="parse_loading">
          <el-icon>
            <Search/>
          </el-icon>
        </el-button>
      </template>
    </el-input>
    <div id="rpm_version_show" :style="'height:' + (height - 140) + 'px'">
      <el-button v-if="Object.keys(single_package_source_data).length!==0" @click="get_email_format" type="success"
                 style="margin-bottom: 4px" plain>
        》》》生成邮件《《《
      </el-button>
      <el-input
          v-if="Object.keys(single_package_source_data).length!==0&&str_email"
          v-model="str_email"
          :autosize="{ minRows: 2, maxRows: 20 }"
          type="textarea"
          placeholder="等待邮件生成"
          style="margin-bottom: 4px"
      />
      <!--      <el-timeline v-loading="koji_parse_loading" v-if="show_type!=='分类显示'">-->
      <!--        <el-timeline-item v-for="(repo, i) in koji_parse_filter" :key="i" :timestamp="repo.tag_arch" placement="top">-->
      <!--          <el-link :href="repo.repo_link" target="_blank" type="info">>>>-->
      <!--            跳转到仓库（{{ repo.repo_link }}）-->
      <!--          </el-link>-->
      <!--          <ol style="margin-left: -22px">-->
      <!--            <li v-for="(repo_rpm_one, r_i) in repo.rpm_src_list" :key="r_i">-->
      <!--              <el-link :href="repo.repo_link" target="_blank">{{ repo_rpm_one }}</el-link>-->
      <!--            </li>-->
      <!--          </ol>-->
      <!--        </el-timeline-item>-->
      <!--      </el-timeline>-->

      <el-collapse v-model="single_package_source_data_show_activate">
        <el-collapse-item v-for="(v, k) in single_package_source_data" :key="k" :title="k" :name="k">
          <el-check-tag v-for="(vv, kk) in v" :key="kk" checked class="package_name_show">{{ vv }}</el-check-tag>
        </el-collapse-item>
      </el-collapse>
    </div>

  </div>
</template>

<script>
import axios from 'axios'
// import check from "@/utils/check";
import {ElNotification} from 'element-plus'
// import windowCodeMirrorComponent from "@/components/windowCodeMirrorComponent";
import {Search} from '@element-plus/icons-vue'

export default {
  name: "windowSinglePackageSourceParseManage",
  props: {
    sessionToken: String,
    codeName: String,
    height: Number
  },
  components: {Search},
  data() {
    return {
      date_str: "",
      str_email: "",
      parse_loading: false,
      rpm_name: "",
      shortcuts: [
        {
          text: '>>> 今天 <<<',
          value: new Date(),
        },
        {
          text: '>>> 昨天 <<<',
          value: () => {
            const date = new Date()
            date.setTime(date.getTime() - 3600 * 1000 * 24)
            return date
          },
        },
      ],
      single_package_source_data_show_activate: [],
      single_package_source_data: {}
    }
  },
  methods: {
    do_copy(copy_str) {
      this.$copyText(copy_str).then(function () {
        ElNotification({title: '复制成功', type: 'success',})
      }, function () {
        ElNotification({title: '复制失败', type: 'error',})
      })
    },
    disabledDate(time) {
      return time.getTime() > Date.now()
    },
    get_single_package_source_info() {
      let obj_this = this
      let data = {
        "session_token": obj_this.sessionToken,
        "rpm_name": this.rpm_name,
        "date": this.date_str
      }
      obj_this.parse_loading = true
      let parse_link = obj_this.$store.state.obj_setting_map.single_package_source_link + "/get_single_package_source_list"
      axios.post(parse_link, data).then(function (response) {
        obj_this.single_package_source_data = response.data.data
        obj_this.single_package_source_data_show_activate = []
        for (let key in obj_this.single_package_source_data)
          obj_this.single_package_source_data_show_activate.push(key)
        obj_this.parse_loading = false
      }).catch(function (error) { // 请求失败处理
        console.log(error);
      });
    },
    get_email_format() {
      let obj_this = this
      let data = {
        "session_token": obj_this.sessionToken,
        "rpm_name": this.rpm_name,
        "date": this.date_str
      }
      let parse_link = obj_this.$store.state.obj_setting_map.single_package_source_link + "/get_email_format"
      obj_this.str_email = "单包源邮件正在生成中。。。"
      axios.post(parse_link, data).then(function (response) {
        obj_this.str_email = response.data.data
      }).catch(function (error) { // 请求失败处理
        console.log(error);
      });
    }
  },
  mounted() {
  }
}
</script>

<style scoped>
#rpm_version_show {
  margin-top: 10px;
  overflow: auto;
}

.package_name_show {
  margin-right: 8px;
  margin-top: 3px;
}
</style>
